---
artifact: {{ .ModuleName }}/build-python-static-artifact
from: {{ .Images.BASE_UBUNTU_DEV }}
git:
- add: /{{ $.ModulePath }}modules/000-{{ $.ModuleName }}/images/{{ $.ImageName }}/Setup.local
  to: /build/Setup.local
  stageDependencies:
    install:
    - '**/*'
shell:
  install:
  - export PYTHON_VERSION=3.11.6 BUILD_THREADS=4 PYTHON_PREFIX=/opt/python-static
  - git clone -b v${PYTHON_VERSION} --single-branch --depth=1 {{ $.SOURCE_REPO }}/python/cpython.git /build/src
  - cp /build/Setup.local /build/src/Modules/Setup.local
  - cd /build/src
  - ./configure LDFLAGS="-static" --disable-shared --prefix=${PYTHON_PREFIX} --enable-optimizations --with-ensurepip=install
  - make LDFLAGS="-static" LINKFORSHARED=" " -j ${BUILD_THREADS}
  - make install -j ${BUILD_THREADS}
  - chown -R 64535:64535 ${PYTHON_PREFIX}
  - chmod 0700 ${PYTHON_PREFIX}/bin/python3
  - chmod 0700 ${PYTHON_PREFIX}/bin/pip3
---
image: {{ $.ModuleName }}/{{ $.ImageName }}
fromImage: common/distroless
import:
- artifact: {{ $.ModuleName }}/build-python-static-artifact
  add: /opt/python-static
  to: /opt/python-static
  before: setup
